﻿@model RXY_Mall.Application.Marketing.Dto.GetBannerOutput


@{
    ViewBag.Title = "添加Banner";
}
@section CSS{
    <link href="~/Content/css/layerui/layui.css" rel="stylesheet" />
}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            @ViewBag.text
            <small>Banner</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">营销管理</a></li>
            <li><a href="/Marketing/Banners">Banner列表</a></li>
            <li class="active">@ViewBag.text Banner</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-body">
                        <div class="ibox float-e-margins">

                            <div class="ibox float-e-margins">
                                <div class="ibox-content">
                                    <form class="form-horizontal" id="from-add" novalidate="novalidate" method="post" action="/Marketing/Banner">

                                        @Html.AntiForgeryToken()
                                        @Html.HiddenFor(model => model.banner_id)
                                        @Html.HiddenFor(model => model.picture_url)

                                        <div class="form-horizontal">
                                            @Html.ValidationSummary(true, "", new { @class = "text-danger" })

                                            <div class="form-group">
                                                <label class="control-label col-md-2">类型</label>
                                                <div class="col-md-10">
                                                    <select class="form-control" id="type_id" name="type_id">
                                                        <option value="1">广告</option>
                                                        <option value="2">主题</option>
                                                        <option value="3">商店</option>
                                                        <option value="4">商品分类</option>
                                                        <option value="5">商品类型</option>
                                                        <option value="6">商品</option>
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.picture_url, htmlAttributes: new { @class = "control-label col-md-2" })
                                                <div class="col-md-10">
                                                    <div class="layui-upload">
                                                        <button type="button" class="layui-btn" id="test1">上传图片</button>
                                                        <input class="layui-upload-file" type="file" accept="undefined" name="file">
                                                        <div class="layui-upload-list">
                                                            <img class="layui-upload-img" id="banner_img" onclick="javascript:imgzoom(this.id)" style="width: 200px; height: 100px; cursor: pointer">
                                                            <p id="demoText1"></p>
                                                        </div>
                                                    </div>
                                                    <span class="help-block m-b-none">图片尺寸：750*290，大小不超过1M</span>
                                                    @Html.ValidationMessageFor(model => model.picture_url, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
                                                <div class="col-md-10">
                                                    @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } })
                                                    @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.content, htmlAttributes: new { @class = "control-label col-md-2" })
                                                <div class="col-md-10">
                                                    @Html.EditorFor(model => model.content, new { htmlAttributes = new { @class = "form-control" } })
                                                    @Html.ValidationMessageFor(model => model.content, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.sort, htmlAttributes: new { @class = "control-label col-md-2" })
                                                <div class="col-md-10">
                                                    @Html.EditorFor(model => model.sort, new { htmlAttributes = new { @class = "form-control" } })
                                                    @Html.ValidationMessageFor(model => model.sort, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.status, htmlAttributes: new { @class = "control-label col-md-2" })
                                                <div class="col-md-10">
                                                    <select class="form-control" id="status" name="status">
                                                        <option value="1">启用</option>
                                                        <option value="0">禁用</option>
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.add_time, htmlAttributes: new { @class = "control-label col-md-2" })
                                                <div class="col-md-10">
                                                    <input type="text" class="form-control" id="add_time" name="add_time" value="@Model.add_time" disabled />
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <div class="col-sm-4 col-sm-offset-3">
                                                <button class="btn btn-primary" type="submit">保存信息</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

</div>

@section JS{
    <script src="~/Content/js/jquery.form.js"></script>
    <script src="~/Content/plugins/validate/jquery.validate.min.js"></script>
    <script src="~/Content/plugins/validate/messages_zh.min.js"></script>
    <script type="text/javascript">

        $(function () {
            $("#type_id").val(@Model.type_id);
            $("#status").val(@Model.status);
            $('#banner_img').attr('src', domain+'@Model.picture_url');
        });

        //图片点击跳转
        function imgzoom(obj) {
            var img = document.getElementById(obj).src
            if (!!img) {
            onclick = window.open(img)
            }
        }
        //后期可重构一个方法
        layui.use('upload', function () {
                    var $ = layui.jquery, upload = layui.upload;
                    //普通图片上传
                    var uploadInst = upload.render({
                    elem: '#test1',
                    url: domain + "/Tools/UploadBannerImg?type=Banner",
                    before: function (obj) {
                        //预读本地文件示例，不支持ie8
                        obj.preview(function (index, file, result) {
                        $('#banner_img').attr('src', result); //图片链接（base64）
                    });
                },
                done: function (res) {
                    $('#banner_img').attr('src', domain + res.info);
                    $('#picture_url').val(sqlImgdomain + res.info);
                },
                error: function () {
                    var demoText = $('#demoText1');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                    });
                    }
                });
         });
    </script>
}
